require("../css/login.less")
document.ready(function(){
    let phoneInp = document.querySelector("#phoneInp")
    let passwordInp = document.querySelector("#passwordInp")
    let submitBtn = document.querySelector("#submitBtn")
    let tips = document.querySelector("#tips")
    submitBtn.addEventListener("click",function(){
        let phone=phoneInp.value
        let password=passwordInp.value
        console.log(tips);
        if(!window.$utils.isPhone(phone)){
            tips.textContent="您输入的手机号有误"
        }else if(!window.$utils.isPassword(password)){
            tips.textContent="您输入的密码有误"
        }else{
            
            tips.innerHTML = ""
            axios.post("http://139.9.177.51:8099/users/login",{
                "account":phone,
                "password":password
            }).then(function(res){
                let ret=res.data
                console.log(res);
                if(ret.status==0){
                    window.$utils.toast()

                    
                    window.setTimeout(function(){
                        window.location.href = "./home.html";
                    },3000)
                    //把个人信息保存到本地存储中
                    window.localStorage.setItem("user",JSON.stringify(ret.data.user))
                   
                }else if(ret.status==555){
                    window.$utils.toast("×","登录失败")
                }
            }).catch(function(err){
                console.log(err);
                
            })
        }
    })
})